package com.javaprint.order.util;

import org.springframework.util.StringUtils;

/**
 *转换数字为中文大写
 * @since 2020/3/24 18:16
 **/
public class ChangeChineseWordUtil {

    public static String changeWord(String field){
        char[] s1 = {'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'};
        char[] s4 = {'分', '角', '元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟', '万'};
        if(StringUtils.isEmpty(field)){
            return "";
        }
        String str =field;
        String result = "";
        for (int i = 0; i <str.length(); i++) {
            int n = str.charAt(str.length() - 1 - i) - '0';
            result = s1[n] + "" + s4[i] + result;
        }
        result = result.replaceAll("零仟", "零");
        result = result.replaceAll("零佰", "零");
        result = result.replaceAll("零拾", "零");
        result = result.replaceAll("零亿", "亿");
        result = result.replaceAll("零万", "万");
        result = result.replaceAll("零元", "元");
        result = result.replaceAll("零角", "零");
        result = result.replaceAll("零分", "零");
        result = result.replaceAll("零零", "零");
        result = result.replaceAll("零亿", "亿");
        result = result.replaceAll("零零", "零");
        result = result.replaceAll("零万", "万");
        result = result.replaceAll("零零", "零");
        result = result.replaceAll("零元", "元");
        result = result.replaceAll("亿万","亿");
        result = result.replaceAll("零$", "");
        result = result.replaceAll("元$", "元整");
        result = result.replaceAll("角$", "角整");
        return result;
    }
}
